<?php
class Futures_history_model extends CI_Model
{

    public function __construct()
    {
        parent::__construct();
        // 加载数据库
        $this->load->database();
    }

    public function insert_batch($data) {
        // 使用 insert_batch 方法进行批量插入
        return $this->db->insert_batch('tw_lucky_cat.futures_history', $data);
    }

    public function selectBySymbol($symbol)
    {
        $this->db->select("*");
        $this->db->from("tw_lucky_cat.futures_history");
        
        $this->db->where('symbol', $symbol);
        $this->db->where('deleted_at', null);
        $this->db->order_by('date', 'DESC');
        
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result();
        }
        return false;
    }

    public function selectFuturesVarietyBySymbol($platform = null)
    {
        $this->db->select("*");
        $this->db->from("tw_lucky_cat.futures_variety");
        
        if ($platform) {
            $this->db->where('platform', $platform);
        }

        $this->db->order_by('variety', 'asc');
        
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result();
        }
        return false;
    }

    public function selectFuturesVarietyDetailBySymbol($platform = null)
    {
        $this->db->select("*");
        $this->db->from("tw_lucky_cat.futures_variety_detail");
        
        if ($platform) {
            $this->db->where('platform', $platform);
        }

        $this->db->order_by('variety_code', 'asc');
        
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result();
        }
        return false;
    }
}